<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 1.想要一个变量自己加   num = num + 1 比较麻烦
        var num = 1;
        num = num + 1;
        num = num + 1;
        console.log(num); //3

        // 2.前置递增(递减)运算符  ++写在变量的前面
        var age = 10;
        console.log(++age + 10); //21 先自加 后返回值
        ++age; //类似于 age = age + 1;
        console.log(age); //12

        // 3.后置递增(递减)运算符  ++写在变量后面
        var ter = 20;
        console.log(ter++ + 10); //30 先返回值 后自加
        ter++;
        console.log(ter); //22

        // 练习
        var a = 10;
        ++a; // a = 11   ++a = 11
        var b = ++a + 2; // a = 12   ++a = 12
        console.log(b); // 14

        var c = 10;
        c++; // c++ = 10   c = 11
        var d = c++ + 2; // c++ = 11   c = 12
        console.log(d); // 13

        var e = 10;
        var f = e++ + ++e; // e++ = 10   e = 11  ++e = 12
        console.log(f); // 22
    </script>
</head>

<body>

</body>

</html>